/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.jar.data.time;

import z.h.w.jar.data.time.period.Period;

/**
 *
 * @author EnzoZhong
 */
public class PlaceAct {

   public Boolean place ( Time self , Place place , Time time ) {
      switch ( place ) {
         case AFTER: {
            return self.getTime () > time.getTime ();
         }
         case BEFORE: {
            return self.getTime () < time.getTime ();
         }
         case LEFT: {
            return self.is ( Place.BEFORE , time );
         }
         case RIGHT: {
            return self.is ( Place.AFTER , time );
         }
         case PASS: {
            return self.is ( Place.BEFORE , Time.born () );
         }
         case FUTURE: {
            return self.is ( Place.AFTER , Time.born () );
         }
         default: {
            throw new Error ( "Time不具备" + place.toString () + "性质！" );
         }
      }
   }

   public Boolean place ( Time time , Period period , Place place ) {
      return place ( period , new Period ( time , time ) , place );
   }

   public Boolean place ( Period self , Period period , Place place ) {
      switch ( place ) {
         case AFTER: {
            return self.getStart ().getTime () > period.getStart ().getTime ();
         }
         case BEFORE: {
            return self.getStart ().getTime () < period.getStart ().getTime ();
         }
         case COINCIDE: {
            Time start1 = self.getStart ();
            Time start2 = period.getStart ();
            Long long1 = self.getTime ();
            Long long2 = self.getTime ();
            return start1.equals ( start2 ) && long1 == long2;
         }
         case INSIDE: {
            Time a = self.getStart ();
            Time b = self.getEnd ();
            Time c = period.getStart ();
            Time d = period.getEnd ();
            if ( a.after ( c ) && b.before ( d ) ) {
               return true;
            }
            return false;
         }
         case OUTSIDE: {
            Time a = self.getStart ();
            Time b = self.getEnd ();
            Time c = period.getStart ();
            Time d = period.getEnd ();
            if ( a.is ( Place.AFTER , d ) || b.is ( Place.BEFORE , c ) ) {
               return true;
            }
            if ( c.is ( Place.AFTER , b ) || d.is ( Place.BEFORE , a ) ) {
               return true;
            }
            return false;
         }
         case LEFT: {
            Time start1 = self.getStart ();
            Time start2 = period.getStart ();
            return start1.is ( Place.BEFORE , start2 );
         }
         case RIGHT: {
            Time start1 = self.getStart ();
            Time start2 = period.getStart ();
            return start1.is ( Place.AFTER , start2 );
         }
         case PASS: {
            /*
             * 特殊情形，判断的是现在这个时候，因此不需要输入时间段
             * pass----period
             *
             * a----b c------d
             */
            Time b = self.getStart ();
            Time c = Time.born ();
            return c.is ( Place.AFTER , b );
         }
      }
      throw new UnsupportedOperationException ( "Not supported yet." );
   }

}
